import os
from dotenv import load_dotenv
from text2sql import SQLRunner
from viz import VizAgent

load_dotenv()
if __name__ == "__main__":
    db_url = os.getenv("DB_URL", "mysql+pymysql://用户名:密码@localhost:3306/mydatabase")
    runner = SQLRunner(db_url)

    # 直接查询或接前一节 NL2SQL 的 df
    df = runner.exec("SELECT product_name, sales_amount FROM sales WHERE year=2023 ORDER BY sales_amount DESC;")
    VizAgent(df).bar(x="product_name", y="sales_amount", title="2023 product sales bar chart")